package makabakaquestionnaire.zutsoftware.framework.manager;

import makabakaquestionnaire.zutsoftware.utils.SpringUtils;
import makabakaquestionnaire.zutsoftware.utils.Threads;

import java.util.TimerTask;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;

public class ExecutorManager {
    /**
     * 操作延迟10毫秒
     */
    private final int OPERATE_DELAY_TIME = 10;
    Executor taskExecutor = SpringUtils.getBean("taskExecutor");


    /**
     * 单例模式,饿汉式加载
     * 私有化构造方法
     */
    private ExecutorManager() {}
    static ExecutorManager executorManager=new ExecutorManager();
    public static ExecutorManager getExecutorManager() {
        return executorManager;
    }

    /**
     * 执行任务
     * @param task
     */
    public void execute(TimerTask task){
        taskExecutor.execute(task);
    }

    /**
     * 关闭线程池
     */
    public void shutdown(){
        Threads.shutdownAndAwaitTermination((ExecutorService) taskExecutor);
    }
}
